package com.ruoyi.common.config.websockert3;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.socket.CloseStatus;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

/**
 * @author Fql18
 * @version 1.0
 * @date 2025-08-19 23:44
 * @description
 */
@Slf4j
public class EchoHandler extends TextWebSocketHandler {
	@Override
	public void afterConnectionEstablished(WebSocketSession session) {
		log.info("🔗 有客户端连上：{}", session.getId());
	}

	@Override
	protected void handleTextMessage(WebSocketSession session, TextMessage message)
		throws Exception {
		log.info("📩 收到：{}", message.getPayload());
		session.sendMessage(new TextMessage("Echo -> " + message.getPayload()));
	}

	@Override
	public void afterConnectionClosed(WebSocketSession session, CloseStatus status) {
		log.info("🔌 客户端断开：{}", session.getId());
	}
}
